package com.line.myprojectservice.controller;

import com.line.myprojectservice.utils.ResponseUtil;
import com.line.myprojectservice.dto.MessageDto;
import com.line.myprojectservice.service.MessageService;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/message")
public class MessageController {

    final MessageService messageService;

    public MessageController(MessageService messageService) {
        this.messageService = messageService;
    }


    @PostMapping
    public ResponseUtil addMessage(@RequestBody MessageDto messageDto) {
        messageService.addMessage(messageDto);
        return ResponseUtil.success();
    }

    @DeleteMapping("/{id}")
    public ResponseUtil delete(@PathVariable String id) {
        messageService.deleteMessageById(id);
        return ResponseUtil.success();
    }

    //根据帖子id查询所有评论
    @GetMapping("/{id}")
    public ResponseUtil queryMessageById(@PathVariable String id) {
        return ResponseUtil.success(messageService.queryMessageById(id));
    }


}
